from pytdx.hq import TdxHq_API
from pytdx.params import TDXParams
import pandas as pd

print("=== 调试通达信数据格式 ===")

# 连接通达信
api = TdxHq_API()
if api.connect('180.153.18.170', 7709):
    print("✅ 连接成功")
    
    # 测试股票数据
    print("\n1. 测试股票数据 (159915):")
    stock_data = api.get_security_bars(
        category=TDXParams.KLINE_TYPE_DAILY,
        market=0,  # 深圳
        code='159915',
        start=0,
        count=3
    )
    
    if stock_data:
        print(f"获取到 {len(stock_data)} 条股票数据")
        print("第一条数据:")
        for key, value in stock_data[0].items():
            print(f"  {key}: {value} ({type(value)})")
    else:
        print("未获取到股票数据")
    
    # 测试指数数据
    print("\n2. 测试指数数据 (000300):")
    index_data = api.get_index_bars(
        category=TDXParams.KLINE_TYPE_DAILY,
        market=1,  # 上海
        code='000300',
        start=0,
        count=3
    )
    
    if index_data:
        print(f"获取到 {len(index_data)} 条指数数据")
        print("第一条数据:")
        for key, value in index_data[0].items():
            print(f"  {key}: {value} ({type(value)})")
    else:
        print("未获取到指数数据")
    
    api.disconnect()
else:
    print("❌ 连接失败")

print("\n=== 调试完成 ===")